
#include "Entity_Waypoints.h"

#include "string.h"

#include "../CASF/CDSF_Types.h"


#define kNumberOfWaypoints		101


static Waypoint m_waypoints[kNumberOfWaypoints];
static int m_toPointIndex = 0;
static bool m_dirty = 0;


int WaypointsCount(){
	return kNumberOfWaypoints;
}

int WaypointsGetToPointIndex(){
	return m_toPointIndex;
}

void WaypointsSetToPointIndex(int index){
	if(index<0||index>=kNumberOfWaypoints)
		return;
	
	m_toPointIndex = index;
}

Waypoint WaypointsGet(int index){
	Waypoint wp = {0};
	
	if(index<0||index>=kNumberOfWaypoints)
		return wp;

	return m_waypoints[index];
}

bool WaypointsCanSet(int index){
	return (index>=m_toPointIndex);
}

void WaypointsSet(int index, Waypoint wp){
	if(index<0||index>=kNumberOfWaypoints)
		return;

	m_waypoints[index] = wp;
	m_dirty = 1;
}

void WaypointsInvalidate(int index){
	m_waypoints[index].valid = 0;
	m_dirty = 1;
}

void WaypointsRemove(int index){
	int i;

	if(index<0||index>=kNumberOfWaypoints)
		return;
	
	for(i=index+1; i<kNumberOfWaypoints; i++)
		m_waypoints[i-1] = m_waypoints[i];
	
	m_waypoints[kNumberOfWaypoints-1].valid = 0;
}

bool WaypointsIsModified(void){
	return m_dirty;
}

void WaypointsResetModified(void){
	m_dirty = 0;
}
